<body class="gr">

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView-x">{if isset($data.category->name)}{$data.category->name}{elseif isset($ext_property) && $ext_property==4}新品发售{else}商品列表{/if}</div>
</div>

<div class="goods-list main-padding-top width-wrap">
	<div class="pullRefresh" category_id="{if isset($category_id)}{$category_id}{/if}">
		<div class="list goods">
			{foreach from=$data.goods name=g item=g}
			<div>
				<a href="wap.php?app=goods&act=detail&id={$g->id}">
					<p style="background-image:url({$g->pic});"></p>
					<span>{$g->name}</span>
					<font>￥{number_format($g->price,2,'.','')}</font>
				</a>
			</div>
			{/foreach}
		</div>
	</div>
</div>

<script>
var offset = $('.pullRefresh .list > div').length;
function createHtml(g){
	var html = '<div>\
		<a href="wap.php?app=goods&act=detail&id='+g.id+'">\
			<p style="background-image:url('+g.pic+');"></p>\
			<span>'+g.name+'</span>\
			<font>￥'+g.price.numberFormat(2)+'</font>\
		</a>\
	</div>';
	offset++;
	return html;
}
function setLists(){
	$('.list a p').loadbackground();
}
$(function(){
	setLists();
	$('html, body, .pullRefresh').addClass('height-wrap');
	$('.goods-list').height($.window().height-$('.goods-list').padding().top);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=goods&act=index{if isset($category_id)}&category_id={$category_id}{/if}{if isset($ext_property)}&ext_property={$ext_property}{/if}{if isset($brand_id)}&brand_id={$brand_id}{/if}{if isset($min_price)}&min_price={$min_price}{/if}{if isset($max_price)}&max_price={$max_price}{/if}{if isset($order_field)}&order_field={$order_field}{/if}{if isset($order_sort)}&order_sort={$order_sort}{/if}', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.goods))for(var i=0; i<json.data.goods.length; i++)html += createHtml(json.data.goods[i]);
				_this.find('.list').html(html);
				setLists();
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=goods&act=index{if isset($category_id)}&category_id={$category_id}{/if}{if isset($ext_property)}&ext_property={$ext_property}{/if}{if isset($brand_id)}&brand_id={$brand_id}{/if}{if isset($min_price)}&min_price={$min_price}{/if}{if isset($max_price)}&max_price={$max_price}{/if}{if isset($order_field)}&order_field={$order_field}{/if}{if isset($order_sort)}&order_sort={$order_sort}{/if}', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.goods))for(var i=0; i<json.data.goods.length; i++)html += createHtml(json.data.goods[i]);
				_this.find('.list').append(html);
				setLists();
				fn();
			});
		}
	});
});
</script>